package com.example.employeemanagement.mapper;

import com.example.employeemanagement.entry.Position;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface PositionMapper {
    @Select("SELECT * FROM position")
    List<Position> getAllPositions();

    @Select("SELECT * FROM position WHERE position_id = #{positionId}")
    Position getPositionById(@Param("positionId") Integer positionId);

    @Select("SELECT COUNT(*) > 0 FROM position WHERE position_id = #{positionId}")
    boolean existsById(@Param("positionId") Integer positionId);

    @Insert("INSERT INTO position (position_name) VALUES (#{positionName})")
    @Options(useGeneratedKeys = true, keyProperty = "positionId")
    int addPosition(Position position);

    @Update("UPDATE position SET position_name = #{positionName} WHERE position_id = #{positionId}")
    int updatePosition(Position position);

    @Delete("DELETE FROM position WHERE position_id = #{positionId}")
    int deletePosition(@Param("positionId") Integer positionId);
}